<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class StoreProduct extends Model
{
    use HasFactory;
    protected $table = 'store_product';
    protected $guarded = [];

    /**
     * 查询一条数据
     * @param $id
     * @return mixed
     */
    public static function find($id){
        return self::where('id',$id)->first();
    }


    /**
     * 查询所有商品
     * @return mixed
     */
    public static function getStoreProduct(){
        return self::get();
    }

    /**
     * @param $id
     * @return Model|\Illuminate\Database\Query\Builder|object|null
     * 订单商品单个查询
     */
    public static function OrderSelect($id)
    {
        return DB::table('store_product')->where('id',$id)
            ->select('id','image','store_name','store_info','price')
            ->first();
    }

    /**
     * 商品预售查询
     * @return mixed
     */
    public static function activeGoods(){
        return self::where('active_status',1)->select(['id','image','store_name','is_postage','postage','active_price','active_time','active_num','slider_image'])->get()->toArray();
    }

    /**
     * 商品预售详情
     * @param $id
     * @return mixed
     */
    public static function activeItem($id){
        return self::where('id',$id)->select(['id','image','store_name','is_postage','postage','active_price','active_time','active_num','active_bargain','store_info','slider_image'])->first();
    }

    //cqf
    public function getActiveTimeAttribute($value)
    {
        return strtotime($value);
    }
}
